package web.beans;

import entity.Car.bo.CarBo;
import entity.Car.model.Car;
import entity.Car.model.Transport;

import javax.faces.event.ValueChangeEvent;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by vanches on 9.1.15.
 */
public class AddCar implements Serializable {
    private CarBean carBean;
    private CarBo carBo;
    private UserBean userBean;


    private int bodyTypeId;
    private int brandId;
    private int colorId;
    private int conditionId;
    private int currencyId;
    private int modelId;
    private int privodId;
    private int transmissionId;
    private int typeEngineId;
    private double price;
    private Date date;
    private String description;
    private double volume;
    private boolean next = false;



    public void bodyTypeSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            bodyTypeId = Integer.parseInt(e.getNewValue().toString());
    }

    public void brandSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            brandId = Integer.parseInt(e.getNewValue().toString());
    }

    public void colorSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            colorId = Integer.parseInt(e.getNewValue().toString());
    }

    public void conditionSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            conditionId = Integer.parseInt(e.getNewValue().toString());
    }

    public void currencySet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            currencyId = Integer.parseInt(e.getNewValue().toString());
    }

    public void modelSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            modelId = Integer.parseInt(e.getNewValue().toString());
    }

    public void privodSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            privodId = Integer.parseInt(e.getNewValue().toString());
    }

    public void transmissionSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            transmissionId = Integer.parseInt(e.getNewValue().toString());
    }

    public void typeEngineSet(ValueChangeEvent e) {
        if (e.getNewValue() != null && !e.getNewValue().toString().isEmpty())
            typeEngineId = Integer.parseInt(e.getNewValue().toString());
    }

    private Transport transport;
    private Car car;
    public void resume() {
        next = true;
         transport=new Transport(carBo.getBrandId(brandId),price,carBo.getCurrencyId(currencyId),date,carBo.getConditionId(conditionId),carBo.getColorId(colorId),description, userBean.getId());
         car=new Car(carBo.getModelId(modelId),transport,carBo.getTypeEngineId(typeEngineId),carBo.getTransmissionId(transmissionId),carBo.getPrivodId(privodId),carBo.getBodyTypeId(bodyTypeId),volume);


    }
    public String addAdver(){
        carBo.addCar(car,transport);
        carBean.init();
        return "auto";
    }

    //region GET and SET

    public CarBean getCarBean() {
        return carBean;
    }

    public void setCarBean(CarBean carBean) {
        this.carBean = carBean;
    }

    public CarBo getCarBo() {
        return carBo;
    }

    public void setCarBo(CarBo carBo) {
        this.carBo = carBo;
    }

    public int getBodyTypeId() {
        return bodyTypeId;
    }

    public void setBodyTypeId(int bodyTypeId) {
        this.bodyTypeId = bodyTypeId;
    }

    public int getBrandId() {
        return brandId;
    }

    public void setBrandId(int brandId) {
        this.brandId = brandId;
    }

    public int getColorId() {
        return colorId;
    }

    public void setColorId(int colorId) {
        this.colorId = colorId;
    }

    public int getConditionId() {
        return conditionId;
    }

    public void setConditionId(int conditionId) {
        this.conditionId = conditionId;
    }

    public int getCurrencyId() {
        return currencyId;
    }

    public void setCurrencyId(int currencyId) {
        this.currencyId = currencyId;
    }

    public int getModelId() {
        return modelId;
    }

    public void setModelId(int modelId) {
        this.modelId = modelId;
    }

    public int getPrivodId() {
        return privodId;
    }

    public void setPrivodId(int privodId) {
        this.privodId = privodId;
    }

    public int getTransmissionId() {
        return transmissionId;
    }

    public void setTransmissionId(int transmissionId) {
        this.transmissionId = transmissionId;
    }

    public int getTypeEngineId() {
        return typeEngineId;
    }

    public void setTypeEngineId(int typeEngineId) {
        this.typeEngineId = typeEngineId;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public double getVolume() {
        return volume;
    }

    public void setVolume(double volume) {
        this.volume = volume;
    }

    public boolean isNext() {
        return next;
    }

    public void setNext(boolean next) {
        this.next = next;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public UserBean getUserBean() {
        return userBean;
    }

    public void setUserBean(UserBean userBean) {
        this.userBean = userBean;
    }

    //endregion
}
